using System.Collections.Generic;
using System.Linq;

namespace QueryBuilder.Core.Query
{
    /// <summary>
    /// 
    /// </summary>
    public class Table : ITable
    {
        /// <summary>
        /// 
        /// </summary>
        private IList<IColumn> columns = new List<IColumn>();
        /// <summary>
        /// 
        /// </summary>
        private IList<IColumn> primaryKeys = new List<IColumn>();

        #region ITable Members

        /// <summary>
        /// Initializes a new instance of the <see cref="Table"/> class.
        /// </summary>
        public Table()
        {
        }

        /// <summary>
        /// Initializes a new instance of the <see cref="Table"/> class.
        /// </summary>
        /// <param name="name">The name.</param>
        public Table(string name)
        {
            this.Name = name;
        }

        /// <summary>
        /// Gets or sets the name.
        /// </summary>
        /// <value>The name.</value>
        public string Name { get; set; }

        /// <summary>
        /// Gets or sets the name of the schema.
        /// </summary>
        /// <value>The name of the schema.</value>
        public string SchemaName { get; set; }

        /// <summary>
        /// Gets the primary keys.
        /// </summary>
        /// <value>The primary keys.</value>
        public IList<IColumn> PrimaryKeys
        {
            get { return this.primaryKeys; }
        }

        /// <summary>
        /// Gets the columns.
        /// </summary>
        /// <value>The columns.</value>
        public IList<IColumn> Columns
        {
            get { return this.columns; }
        }

        /// <summary>
        /// Gets the column.
        /// </summary>
        /// <param name="columnName">Name of the column.</param>
        /// <returns></returns>
        public IColumn GetColumn(string columnName)
        {
            return this.Columns.FirstOrDefault((c) => string.Equals(c.Name, columnName));
        }

        #endregion
    }
}